package com.zhj.interview;

import java.util.concurrent.*;

public class Test100 {

    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(
                3
                ,5
                ,3
                , TimeUnit.SECONDS
                , new LinkedBlockingQueue(3)
                , new MyThreadFactory()
                ,new ThreadPoolExecutor.CallerRunsPolicy()
        );
        MyTask myTask = new MyTask();
        Future<?> submit = executorService.submit(myTask);
    }

    private static class MyThreadFactory implements ThreadFactory {

        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r);
            thread.setName("MyThread-Test-");
            return thread;
        }
    }

}
class MyTask implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println( Thread.currentThread().getName() + i);
        }
    }
}
